<template>
	<view class="content">
		<view class="top">
			<uni-nav-bar title="修改密码" backgroundColor="transparent" :border="false" leftIcon="left" @clickLeft="back"
				fixed></uni-nav-bar>
			<view class="box">
				<view class="avatar">
					<u-avatar class="avatar-item" :src="avatar" size="80" style="border: 1rpx solid #ff5500;"></u-avatar>
				</view>
				<view class="form" >
					<view class="item">
						<view class="label">
							<text class="icon-jiesuo iconfont" style="font-size: 40rpx;"></text>
							<text class="label-text">旧密码</text>
						</view>
						<view class="input">
							<u--input placeholder="请输入..." fontSize="20" placeholder-style="color:red;" border="none" clearable password v-model="resetForm.old_password"></u--input>
						</view>
					</view>
					<view class="item">
						<view class="label">
							<text class="icon-jiesuo iconfont" style="font-size: 40rpx;"></text>
							<text class="label-text">新密码</text>
						</view>
						<view class="input">
							<u--input placeholder="请输入..." fontSize="20" placeholder-style="color:red;" border="none" clearable password v-model="resetForm.password"></u--input>
						</view>
					</view>
					<view class="item">
						<view class="label" style="display: flex;">
							<text class="icon-jiesuo iconfont" style="font-size: 40rpx;"></text>
							<text class="label-text">确认新密码</text>
						</view>
						<view class="input">
							<u--input placeholder="请输入..." fontSize="20" placeholder-style="color:red;" border="none" clearable password
								v-model="resetForm.ret_password"></u--input>
						</view>
					</view>
				</view>
				<view class="btn">
					<view class="login">
						<view class="login-btn" @click="login">
							确认修改
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: '',
				resetForm: {
					old_password: '',
					password: '',
					ret_password: ''
				},
				checkForm:{},
				settingData:{}
			}
		},
		onLoad() {
			this.memberHome=uni.getStorageSync('memberHome')
			this.checkForm.mobile = this.memberHome.mobile
			this.checkForm.nickname = this.memberHome.nick
			this.checkForm.avatar = this.memberHome.avatar
			if(this.checkForm.avatar && !this.checkForm.avatar.includes('http') ){
				this.checkForm.avatar = this.$store.state.user.baseURL + this.checkForm.avatar
			}
			this.settingData = uni.getStorageSync('settingData')
			this.avatar = this.checkForm.avatar || this.settingData.image
		},
		methods: {
			login() {
				if (!this.resetForm.old_password) {
					uni.showToast({
						title: '请输入旧密码',
						icon: 'none'
					});
					return
				}
				if (!this.resetForm.password) {
					uni.showToast({
						title: '请输入新密码',
						icon: 'none'
					});
					return
				}
				if (this.resetForm.password.length < 6) {
					uni.showToast({
						title: '密码至少为六位',
						icon: 'none'
					});
					return
				}
				if (this.resetForm.ret_password !== this.resetForm.password) {
					uni.showToast({
						title: '两次密码不一致',
						icon: 'none'
					});
					return
				}
				this.$api.reset(this.resetForm).then(res => {
					uni.showModal({
						title: '提示',
						content: "操作成功，即将返回",
						complete: (res) => {
							if(res.confirm){
								uni.navigateBack()
							}
						}
					})
				}).catch(err => {
					console.log(err);
				})
			},
			back() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.top {
		padding-top: 80rpx
	}

	.content {
		background: url('@/static/img/bg1.png') no-repeat;
		background-size: 100% 100%;
		min-height: 100vh;
		z-index: -1;

		.box {
			padding: 0 30rpx;
		}
	}
	.item {
		padding: 40rpx 0 20rpx;
		border-bottom: 1px solid #ff5500;
		.input{
			padding-top: 6rpx;
		}
	}
	.avatar {
		padding-top: 100rpx;

		.avatar-item {
			margin: 0 auto;
		}
	}

	.label {
		font-family: PingFangSC, PingFang SC;
		font-weight: 600;
		font-size: 40rpx;
		color: #111111;
		line-height: 40rpx;
		text-align: left;
		font-style: normal;
		padding-bottom: 20rpx;

		.label-text {
			padding-left: 20rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 40rpx;
			color: #111111;
			line-height: 40rpx;
			text-align: left;
			font-style: normal;
		}
	}

	.btn {
		padding-top: 80rpx;

		.login {
			display: flex;
			justify-content: center;

			.login-btn {
				width: 630rpx;
				height: 84rpx;
				background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
				border-radius: 16rpx;
				line-height: 84rpx;
				text-align: center;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 36rpx;
				color: #FFFFFF;
				font-style: normal;
			}
		}
	}

	.blue {
		color: #347ced;
	}
</style>